package nccu.model;

import com.thoughtworks.xstream.annotations.XStreamAlias;
import com.thoughtworks.xstream.annotations.XStreamConverter;
import nccu.converter.AccountValueConverter;
import org.compass.annotations.Searchable;
import org.compass.annotations.SearchableId;

import javax.persistence.*;
import javax.xml.bind.annotation.XmlRootElement;
import java.io.Serializable;
import java.math.BigDecimal;

@Entity
@Table(name = "account_value")
@Searchable
@XmlRootElement
public class AccountValue extends BaseObject implements Serializable {
    private static final long serialVersionUID = 4617859655331969141L;

    private Long id;
    @XStreamAlias("AccountCode")
    private String accountCode;
    @XStreamAlias("Value")
    @XStreamConverter(value=AccountValueConverter.class)
    private BigDecimal value;
    private Long submission_id;

    public AccountValue(){}

    @Id
    @GeneratedValue(strategy = GenerationType.AUTO)
    @SearchableId
    @Column(name="accountvalue_id")
    public Long getId() {
        return id;
    }

    public void setId(Long id) {
        this.id = id;
    }

    @Column(name="account_code", nullable = false, length = 10)
    public String getAccountCode() {
        return accountCode;
    }

    public void setAccountCode(String accountCode) {
        this.accountCode = accountCode;
    }

    @Column(name="account_value", nullable = false, length = 10, unique = false)
    public BigDecimal getValue() {
        return value;
    }

    public void setValue(BigDecimal value) {
        this.value = value;
    }

    @Column(name="submission_id", nullable = false, length = 10, unique = false)
    public Long getSubmission_id() {
        return submission_id;
    }

    public void setSubmission_id(Long submission_id) {
        this.submission_id = submission_id;
    }

    @Override
    public boolean equals(Object o) {
        if (this == o) return true;
        if (!(o instanceof AccountValue)) return false;

        AccountValue that = (AccountValue) o;

        if (!accountCode.equals(that.accountCode)) return false;
        if (!submission_id.equals(that.submission_id)) return false;
        if (value != null ? !value.equals(that.value) : that.value != null) return false;

        return true;
    }

    @Override
    public int hashCode() {
        int result = accountCode.hashCode();
        result = 31 * result + (value != null ? value.hashCode() : 0);
        result = 31 * result + submission_id.hashCode();
        return result;
    }

    @Override
    public String toString() {
        return "AccountValue{" +
                "id=" + id +
                ", accountCode='" + accountCode + '\'' +
                ", value=" + value +
                ", submission_id=" + submission_id +
                '}';
    }
}
